const CryptoJs = require('crypto-js')

// hook DES 解密
const DES_backup = CryptoJs.DES.decrypt
CryptoJs.DES.decrypt = function (message, key, obj) {
    debugger;
    console.log("Hook DES 解密前的数据 -->> ", message)
    return DES_backup(message, key, obj)
}

function encryptData(message, key) {
    const keyHex = CryptoJs.enc.Utf8.parse(key);
    const encrypted = CryptoJs.DES.encrypt(message, keyHex, {
        mode: CryptoJs.mode.ECB,
        padding: CryptoJs.pad.Pkcs7,
    });
    return encrypted.toString();
}

function decryptData(ciphertext, key) {
    const keyHex = CryptoJs.enc.Utf8.parse(key);
    const decrypted = CryptoJs.DES.decrypt(ciphertext, keyHex, {
        mode: CryptoJs.mode.ECB,
        padding: CryptoJs.pad.Pkcs7,
    });
    return decrypted.toString(CryptoJs.enc.Utf8);
}


const message = "今天是星期一"
const key = 'secret'

console.log(encryptData(message, key))
console.log(decryptData(encryptData(message, key), key))